import { onMounted, onUnmounted } from "vue";

const useKeyboardEvent = () => {
  const handleKeyDown = (event: KeyboardEvent) => {
    console.log(`Key down: ${event.key}`);
  };

  const handleKeyUp = (event: KeyboardEvent) => {
    console.log(`Key up: ${event.key}`);
  };

  onMounted(() => {
    window.addEventListener("keydown", handleKeyDown);
    window.addEventListener("keyup", handleKeyUp);
  });

  onUnmounted(() => {
    window.removeEventListener("keydown", handleKeyDown);
    window.removeEventListener("keyup", handleKeyUp);
  });
};

export { useKeyboardEvent };
